package cn.house.action;

import java.util.Date;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import cn.house.entity.User;
import cn.house.service.UserService;
import cn.house.service.UserServiceImpl;

public class UserAction extends ActionSupport {

	private String name = "";
	private String password = "";
	private Date birthday;

	//值栈
//	private String message;

	private UserService userService = new UserServiceImpl();

	/**
	 * 登录
	 * 
	 * @return
	 */
	public String login() {
		System.out.println(birthday);
		User user = userService.login(name, password);
		if (user != null) {
			ActionContext.getContext().getSession().put("userSession", user);
			if (user.getIsAdmin().equals("是")) {
				return "manage";
			}
			return "login_success";
		}
//		this.setMessage("用户名密码错误!");
		//request 非值栈
		ServletActionContext.getRequest().setAttribute("message", "用户名密码错误!");
		System.out.println("进入Action");
		return "login_error";
	}

	public String register() {

		return Action.SUCCESS;
	}

//	public String getMessage() {
//		return message;
//	}
//
//	public void setMessage(String message) {
//		this.message = message;
//	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

}
